<?php 
class ControllerMessageAuxiliaryPolice extends Controller {
	
	public function all(){
		$this->language->load('message/auxiliary_police');
		$this->load->model('message/auxiliary_police');
		$this->load->model('message/community');
		$this->data['breadcrumbs'] = array();

		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home'),
			'separator' => false
		);

		$this->data['policeInfos'] = array();
		$this->load->model('tool/image');
		$policeInfos = $this->model_message_auxiliary_police->getAuxiliaryPolices();
			$this->document->setTitle("协警信息");
			$this->data['heading_title'] ="协警信息";
			foreach ($policeInfos as $policeInfo) {
				if ($policeInfo['pic_url'] && file_exists(DIR_IMAGE . $policeInfo['pic_url'])) {
					$image = $this->model_tool_image->resize($policeInfo['pic_url'], 100, 80);
				} else {
					$image = $this->model_tool_image->resize('no_image.jpg', 100, 80);
				}
				$this->data['policeInfos'][] = array(
					'image' =>$image,
					'police_code' =>$policeInfo['police_code'],
					'address' =>$policeInfo['address'],
					'dianhua' =>$policeInfo['dianhua'],
					'community_name' =>$policeInfo['community_name'],
					'police_position' =>$policeInfo['police_position'],
					'href'=>$this->url->link('message/auxiliary_police/info', 'auxiliary_police_id='.$policeInfo['auxiliary_police_id'], 'SSL'),
					'title' =>$policeInfo['title'],
					'phone_num' =>$policeInfo['phone_num'],
					'summary' =>$policeInfo['summary'],
				);
			}
			
			$this->data['continue'] = $this->url->link('common/home');

			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/message/auxiliary_police_all.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/message/auxiliary_police_all.tpl';
			} else {
				$this->template = 'default/template/message/auxiliary_police_all.tpl';
			}

			$this->children = array(
				'common/column_left',
				'common/column_right',
				'common/content_top',
				'common/content_bottom',
				'common/footer',
				'common/header'
			);

			$this->response->setOutput($this->render());
	}
	

	public function info() {
		$this->language->load('message/auxiliary_police');

		$this->load->model('message/auxiliary_police');

		$this->data['breadcrumbs'] = array();

		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home'),
			'separator' => false
		);

		if (isset($this->request->get['auxiliary_police_id'])) {
			$auxiliary_police_id = (int)$this->request->get['auxiliary_police_id'];
		} else {
			$auxiliary_police_id = 0;
		}

		$police_info = $this->model_message_auxiliary_police->getAuxiliaryPolice($auxiliary_police_id);
		if ($police_info) {
			$this->document->setTitle($police_info['title']);
			$this->load->model('tool/image');
			$this->data['breadcrumbs'][] = array(
				'text'      => $police_info['title'],
				'href'      => $this->url->link('message/auxiliary_police', 'auxiliary_police_id=' .  $auxiliary_police_id),      		
				'separator' => $this->language->get('text_separator')
			);

			$this->data['heading_title'] = $police_info['title'];

			$this->data['button_continue'] = $this->language->get('button_continue');
			if ($police_info['pic_url'] && file_exists(DIR_IMAGE . $police_info['pic_url'])) {
					$image = $this->model_tool_image->resize($police_info['pic_url'], 100,80);
				} else {
					$image = $this->model_tool_image->resize('no_image.jpg', 100, 80);
				}
				$this->data['address'] =$police_info['address'];
				$this->data['dianhua'] =$police_info['dianhua'];
			$this->data['police_code'] =$police_info['police_code'];
			$this->data['police_position'] =$police_info['police_position'];
			$this->data['title'] = $police_info['title'];
			$this->data['phone_num'] = $police_info['phone_num'];
			$this->data['image'] = $image;
			$this->data['href'] = $this->url->link('message/auxiliary_police/info', 'auxiliary_police_id='.$police_info['auxiliary_police_id'], 'SSL');
			$this->data['description'] = html_entity_decode($police_info['description'], ENT_QUOTES, 'UTF-8');

			$this->data['continue'] = $this->url->link('common/home');

			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/message/auxiliary_police.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/message/auxiliary_police.tpl';
			} else {
				$this->template = 'default/template/message/auxiliary_police.tpl';
			}

			$this->children = array(
				'common/column_left',
				'common/column_right',
				'common/content_top',
				'common/content_bottom',
				'common/footer',
				'common/header'
			);

			$this->response->setOutput($this->render());
		} else {
			$this->data['breadcrumbs'][] = array(
				'text'      => $this->language->get('text_error'),
				'href'      => $this->url->link('message/article', 'police_id=' . $police_id),
				'separator' => $this->language->get('text_separator')
			);

			$this->document->setTitle($this->language->get('text_error'));

			$this->data['heading_title'] = $this->language->get('text_error');

			$this->data['text_error'] = $this->language->get('text_error');

			$this->data['button_continue'] = $this->language->get('button_continue');

			$this->data['continue'] = $this->url->link('common/home');

			$this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . '/1.1 404 Not Found');

			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
			} else {
				$this->template = 'default/template/error/not_found.tpl';
			}

			$this->children = array(
				'common/column_left',
				'common/column_right',
				'common/content_top',
				'common/content_bottom',
				'common/footer',
				'common/header'
			);

			$this->response->setOutput($this->render());
		}
	}
}
?>